package com.admin.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.UUID;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;


public class CreateData {
	 public static String getUUID() {  
	        /*UUID uuid = UUID.randomUUID();  
	        String str = uuid.toString();  
	        // 去掉"-"符号  
	        String temp = str.substring(0, 8) + str.substring(9, 13)  
	                + str.substring(14, 18) + str.substring(19, 23)  
	                + str.substring(24);  
	        return temp;*/  
	          
	        return UUID.randomUUID().toString().replace("-", "");  
	    } 
	    public static String RandomStr(String[] strs){
	        int random_index = (int) (Math.random()*strs.length);
	        return strs[random_index];
	    }
	    public static String getIncreDate(int i){
	    	SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	    	return sd.format(new Date(System.currentTimeMillis()+i*43200000));
	    }
		public static String getRandomString(int length) { //length表示生成字符串的长度  
		    String base = "abcdefghijklmnopqrstuvwxyz0123456789";     
		    Random random = new Random();     
		    StringBuffer sb = new StringBuffer();     
		    for (int i = 0; i < length; i++) {     
		        int number = random.nextInt(base.length());     
		        sb.append(base.charAt(number));     
		    }     
		    return sb.toString();     
		 } 
		public static void createAdmin_user(){
			 Connection connection = null;  
		     PreparedStatement preparedStatement = null;  
			String sql;
        	try {
				connection = JDBCTools.getConnection();
				for(int i=0;i<15;i++){
					sql="insert into admin_user(id,username,password,zsxm,sjhm,szdw,zz) values('"+getUUID()+"','"+getRandomString(6)+"','123456','"+RandomValue.getChineseName()+"','"+RandomValue.getTel()+"','交警支队','"+RandomValue.getRoad()+"')";
					preparedStatement = (PreparedStatement) connection.prepareStatement(sql);  
					preparedStatement.executeUpdate(); 
				}
				
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}  
			
		}
		public static void createAdmin_ptczrz(){
			Connection connection = null;  
			PreparedStatement preparedStatement = null;  
			String sql;
			try {
				connection = JDBCTools.getConnection();
				String [] yhm={"admin","wq0jih","3i9b72","dm0lfw","tnqkyq","2v3lek","opy7al","e41fga","xodusp"};
				String [] czmc={"登录","查看用户","修改用户","账户交易查询"};
				for(int i=0;i<15;i++){
					sql="insert into admin_ptczrz(id,yhm,czmc,czsj) values('"+getUUID()+"','"+RandomStr(yhm)+"','"+RandomStr(czmc)+"','"+getIncreDate(i)+"')";
					preparedStatement = (PreparedStatement) connection.prepareStatement(sql);  
					preparedStatement.executeUpdate(); 
				}
				
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}  
			
		}
		public static void createAdmin_gwczrz(){
			Connection connection = null;  
			PreparedStatement preparedStatement = null;  
			String sql;
			try {
				connection = JDBCTools.getConnection();
				String [] yhm={"admin","wq0jih","3i9b72","dm0lfw","tnqkyq","2v3lek","opy7al","e41fga","xodusp"};
				String [] czlx={"增加","修改","删除"};
				for(int i=0;i<15;i++){
					sql="insert into admin_gwczrz(id,yhm,czlx,gwid,czsj) values('"+getUUID()+"','"+RandomStr(yhm)+"','"+RandomStr(czlx)+"','"+getUUID()+"','"+getIncreDate(i)+"')";
					preparedStatement = (PreparedStatement) connection.prepareStatement(sql);  
					preparedStatement.executeUpdate(); 
				}
				
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}  
			
		}
		public static void createAdmin_gwckrz(){
			Connection connection = null;  
			PreparedStatement preparedStatement = null;  
			String sql;
			try {
				connection = JDBCTools.getConnection();
				String [] yhm={"admin","wq0jih","3i9b72","dm0lfw","tnqkyq","2v3lek","opy7al","e41fga","xodusp"};
				for(int i=0;i<15;i++){
					sql="insert into admin_gwckrz(id,yhm,fwurl,fwsj) values('"+getUUID()+"','"+RandomStr(yhm)+"','http://www.hunan.gov.cn/2015xxgk/fz/zfwj/szfbgtwj/201707/t20170714_4312800.html','"+getIncreDate(i)+"')";
					preparedStatement = (PreparedStatement) connection.prepareStatement(sql);  
					preparedStatement.executeUpdate(); 
				}
				
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}  
			
		}
		public static String getTime_201706_201710(){
			String re="";
			SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd");
			Date start;
			Date end;
			try {
				start=sd.parse("2017-06-05");
				end=sd.parse("2017-10-05");
				long cha=end.getTime()-start.getTime();
				long time=start.getTime()+(long)(cha*Math.random());
				Date d=new Date(time);
				re=sd.format(d);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			return re;
		}
		public static void createAdmin_wjcxrz(){
			Connection connection = null;  
			PreparedStatement preparedStatement = null;  
			String sql;
			try {
				connection = JDBCTools.getConnection();
				String [] yhm={"admin","wq0jih","3i9b72","dm0lfw","tnqkyq","2v3lek","opy7al","e41fga","xodusp"};
				for(int i=0;i<10000;i++){
					String wh="湘发〔2017〕"+i+"号";
					sql="insert into admin_wjcxrz(id,ckr,wh,wjhs,time) values('"+getUUID()+"','"+RandomStr(yhm)+"','"+wh+"','"+getUUID()+"','"+getTime_201706_201710()+"')";
					preparedStatement = (PreparedStatement) connection.prepareStatement(sql);  
					preparedStatement.executeUpdate(); 
				}
				
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}  
			
		}
		public static void main(String[] args) {
			createAdmin_wjcxrz();
		}
			
}
